import { createRouter, createWebHistory } from 'vue-router'
import { scrollBehavior } from './scrollBehavior'
import { createRouterGuards } from './routerGuards'
import { basicRoutes } from './routes'

/**
 * routes路由结构说明
 *
 * path                     路由
 * linkSrc                  定义的外链跳转，如：‘https://baidu.com’，此参数会替换掉path跳转
 * name                     路由name
 * component                页面组件，可选layout枚举："@/router/constant.js"
 * meta                     meta
 * meta.title               页面标题
 * meta.requireAuth         开启访问权限
 * meta.authMark            权限标识，用于处理菜单权限
 * meta.sortIndex           菜单路由排序
 * meta.noKeepAlive         关闭KeepAlive
 * meta.affix               开启tabview模式下，固定显示项
 * meta.hideMenu            是否在菜单中隐藏
 * meta.icon                菜单icon
 * meta.img                 菜单icon图片
 * meta.highlight           菜单高亮
 * children                 子菜单，同父级
 */

const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_PUBLIC_PATH),
  routes: basicRoutes,
  scrollBehavior: scrollBehavior
})

// config router
export function setupRouter(app) {
  app.use(router)
  createRouterGuards(router)
}

export default router
